import { ConfigEnv, defineConfig, loadEnv } from "vite";
import { fileURLToPath, URL } from "url";
import PluginConfig from "./viteConfig/PluginConfig";
import { Server, Build, Css } from "./viteConfig/Config";

export default defineConfig(({ mode }: ConfigEnv) => {
    //获取当前环境变量
    const env = loadEnv(mode, process.cwd());

    return {
        plugins: [...PluginConfig(env)],
        resolve: {
            //设置文件系统路径的别名
            alias: {
                "@": fileURLToPath(new URL("./src", import.meta.url)),
            },
        },

        //开发选项
        server: Server(env),

        //打包构建选项
        build: Build(env),

        //css处理，在打包时不报@charset的警告
        css: Css(),
    };
});
